package com.niit.syy.unitpricebyhouseaddr;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class UnitPriceByHouseAddrMapper extends Mapper<LongWritable, Text, Text, LongWritable> {
    private Text outk = new Text();
    private LongWritable outv = new LongWritable();

    /**
     * map阶段核心业务逻辑（）
     *
     * @param key     偏移量
     * @param value   一行数据,0,成华,驷马桥,3室2厅1厨1卫,高楼层 (共6层),111.02,平层,板...
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String lineData = value.toString();
        String[] datas = lineData.split(",");
        if (datas.length >= 15) {
            outk.set(datas[2]);// 驷马桥...
            outv.set(Long.parseLong(datas[15]));// 10200...
            context.write(outk, outv);
        }
    }
}
